--Warlock Rotations
local lastuacast = 0
local lastpetcast = 0;
local lastimmolatecast = 0;
local lasthauntcast = 0;
local lastsoulfirecast = 0;
local soulswap = false;
local seedcast = false;
local lastsboltcast = 0;

-----------------------------
---------Affliction----------
-----------------------------

---Alysrazor Flying---
function AffLockAlysRot()
	local hasFocus = false
	if CJ_OC() then StopAttack() return end
	--CJ_PetInterrupt("Spell Lock");
	
	--if UnitExists("pet") and not IsPetAttackActive() then
	--	PetAttack("target")
	--end

	if AmIFacing == false then return end;
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
	if CJ_AffBuffs() then return end;
	
	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end
	
	if IsSpellInRange("Fel Flame") == 0 then return end;
	
	
	if GetUnitSpeed("player") > 0 then
		if not CJ_OD("Curse of the Elements") and not CJ_OD("Jinx: Curse of the Elements") then
			if CJ_Cast("Curse of the Elements") then return end;
		end
		
		if CJ_DTR("Corruption") < 2 then
			if CJ_Cast("Corruption") then return end;
		end
		
		if not CJ_HD("Bane of Agony") then
			if CJ_Cast("Bane of Agony") then return end;
		end
				
		if CJ_HB("Shadow Trance") then
			if CJ_Cast("Shadow Bolt") then return end
		end
		
		if PlayerToTarget < 10 then
			if CJ_Cast("Shadowflame") then return end;
		end

		if CJ_Cast("Fel Flame") then return end
		return
	end
	
	if not CJ_OD("Curse of the Elements") and not CJ_OD("Jinx: Curse of the Elements") then
		if CJ_Cast("Curse of the Elements") then return end;
	end
			
	if CJ_HSD("Alysra's Razor") and IsEquippedItem("Rune of Zeth") == 1 and GetItemCooldown(68998) == 0 and IsUsableItem("Rune of Zeth") == 1 and cj_cooldowns then
 		RunMacroText("/use Rune of Zeth");
 		return
	end

	if cj_cooldowns and CJ_HSD("Alysra's Razor") then
		CJ_Cast("Demon Soul");
		CJ_Cast("Blood Fury");
	end

	if IsEquippedItem("Rune of Zeth") == 1 and GetItemCooldown(68998) == 0 and IsUsableItem("Rune of Zeth") == 1 and cj_cooldowns then
 		RunMacroText("/use Rune of Zeth");
 		return
	end

	if cj_cooldowns then
		CJ_Cast("Demon Soul");
		CJ_Cast("Blood Fury");
	end

	---SPECIAL RULES FOR ALYSRAZOR ON GROUND:  Uncomment if you are on ground---
	--if (UnitName("target") ~= "Alysrazor") then
	--	if not UnitCastingInfo("player") and CJ_DTRF("Corruption") < 2 and PlayerToFocus < 40 then
	--		if CJ_CastTarget("Corruption","focus") then return end
	--	end
	
	--	if not UnitCastingInfo("player") and not CJ_HDF("Bane of Doom") and PlayerToFocus < 40 then
	--		if CJ_CastTarget("Bane of Doom","focus") then return end
	--	end
	
	--	if not UnitCastingInfo("player") and (CJ_DTRF("Unstable Affliction") - (select(7,GetSpellInfo("Unstable Affliction"))/1000)) < 2 and (GetTime() - lastuacast > 2.5) 
	--	and GetUnitSpeed("player") == 0 and PlayerToFocus < 40 then
	--		if CJ_CastTarget("Unstable Affliction","focus") then lastuacast = GetTime() return end
	--	end
	--end
	
	
	if not UnitCastingInfo("player") and (CJ_DTR("Haunt") - (select(7,GetSpellInfo("Haunt"))/1000)) < 5 and (GetTime() - lasthauntcast > 3.5) then
		if CJ_Cast("Haunt") then lasthauntcast = GetTime() return end
	end

	if not UnitCastingInfo("player") and (CJ_DTR("Unstable Affliction") - (select(7,GetSpellInfo("Unstable Affliction"))/1000)) < 4 and (GetTime() - lastuacast > 2.5) then
		if CJ_Cast("Unstable Affliction") then lastuacast = GetTime() return end
	end

	if not UnitCastingInfo("player") and CJ_DTR("Corruption") < 2 then
		if CJ_Cast("Corruption") then return end;
	end

	if not CJ_HD("Bane of Agony") then
		if CJ_Cast("Bane of Agony") then return end;
	end
	
	if not UnitCastingInfo("player") and CJ_HSD("Alysra's Razor") or CJ_SDS("Blazing Power") > 9 and (select(1,UnitChannelInfo("player")) ~= "Drain Soul") then
		if CJ_Cast("Drain Soul") then return end
	end
	
	if CJ_HP("target") < 25 and (select(1,UnitChannelInfo("player")) ~= "Drain Soul") then
		if CJ_Cast("Drain Soul") then return end
	end
	
	if select(1,UnitChannelInfo("player")) == "Drain Soul" then return end
	
	if not UnitCastingInfo("player") and PlayerToTarget < 10 then
		if CJ_Cast("Shadowflame") then return end;
	end

	if not UnitCastingInfo("player") and CJ_HB("Shadow Trance") then
		if CJ_Cast("Shadow Bolt") then return end
	end
	
	if not UnitCastingInfo("player") then
		if CJ_Cast("Shadow Bolt") then return end
	end
end

---Begining Aff PVP Rotations---
function AffLockPvpRot()
	local hasFocus = false
	if CJ_OC() then StopAttack() return end
	CJ_PetInterrupt("Spell Lock");
	
	if UnitExists("pet") and not UnitIsDeadOrGhost("pet") and not IsPetAttackActive() then
		PetAttack("target")
	end

	if UnitExists("focus") and UnitCanAttack("player","focus") and (UnitName("focus") ~= "Maloriak" or UnitName("focus") ~= "Majordomo Staghelm" or UnitName("focus") ~= "Shannox" or UnitName("focus") ~= "Riplimb" or UnitName("focus") ~= "Rageface") and UnitGUID("target") ~= UnitGUID("focus") then
		hasFocus = true
	else
		hasFocus = false;
	end

	if AmIFacing == false then return end;
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
	if CJ_AffBuffs() then return end;
	
	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end
	
	if IsSpellInRange("Fel Flame") == 0 then return end;
	
	CJ_OffensiveDispelPet("Devour Magic");
	
	if not UnitCastingInfo("player") and CJ_HB("Soul Swap") and hasFocus and PlayerToFocus < 40 and not (UnitGUID("target") == UnitGUID("focus")) and not (UnitDebuff("focus","Fear") or UnitDebuff("focus","Banish") or UnitDebuff("focus","Howl of Terror") or UnitDebuff("focus","Seduction")) then
		if CJ_CastTarget("Soul Swap","focus") then return end;
	end
	
	if GetUnitSpeed("player") > 0 then
		if not UnitCastingInfo("player") and (UnitClass("target") == "Warrior" or UnitClass("target") == "Death Knight" or UnitClass("target") == "Rogue" or UnitClass("target") == "Hunter") and PlayerToTarget < 8 then
			if CJ_Cast("Howl of Terror") then return end
		end
		
		if not UnitCastingInfo("player") and (UnitClass("target") == "Warrior" or UnitClass("target") == "Death Knight" or UnitClass("target") == "Rogue" or UnitClass("target") == "Hunter") and not CJ_HD("Curse of Exhaustion") then
			if CJ_Cast("Curse of Exhaustion") then return end
		end

		if not UnitCastingInfo("player") and (UnitClass("target") == "Priest" or UnitClass("target") == "Warlock" or UnitClass("target") == "Mage" or UnitClass("target") == "Shaman") and not CJ_HD("Curse of Tongues") then
			if CJ_Cast("Curse of Tongues") then return end
		end
		
		if not UnitCastingInfo("player") and (UnitClass("target") == "Paladin" or UnitClass("target") == "Druid") and (UnitPowerMax("target") > 30000) and not CJ_HD("Curse of Tongues") then
			if CJ_Cast("Curse of Tongues") then return end
		end
		
		if not CJ_HD("Bane of Agony") then
			if CJ_Cast("Bane of Agony") then return end;
		end

		if PlayerToTarget < 10 then
			if CJ_Cast("Shadowflame") then return end;
		end

		if CJ_DTR("Corruption") < 2 then
			if CJ_Cast("Corruption") then return end;
		end
		
		if CJ_HB("Shadow Trance") then
			if CJ_Cast("Shadow Bolt") then return end
		end
		
		if CJ_Cast("Fel Flame") then return end
		return
	end

	if not UnitCastingInfo("player") and (UnitClass("target") == "Warrior" or UnitClass("target") == "Death Knight" or UnitClass("target") == "Rogue" or UnitClass("target") == "Hunter") and PlayerToTarget < 8 then
		if CJ_Cast("Howl of Terror") then return end
	end

	---Trinket code here---
	--if IsEquippedItem("Rune of Zeth") == 1 and GetItemCooldown(68998) == 0 and IsUsableItem("Rune of Zeth") == 1 and cj_cooldowns then
 	--	RunMacroText("/use Rune of Zeth");
 	--	return
	--end

	if cj_cooldowns then
		CJ_Cast("Demon Soul");
		CJ_Cast("Blood Fury");
	end

	if not UnitCastingInfo("player") and CJ_HB("Shadow Trance") then
		if CJ_Cast("Shadow Bolt") then return end
	end

	if not UnitCastingInfo("player") and PlayerToTarget < 10 then
		if CJ_Cast("Shadowflame") then return end;
	end

	if not UnitCastingInfo("player") and (CJ_DTR("Unstable Affliction") - (select(7,GetSpellInfo("Unstable Affliction"))/1000)) < 4 and (GetTime() - lastuacast > 2.5) then
		if CJ_Cast("Unstable Affliction") then lastuacast = GetTime() return end
	end

	if not UnitCastingInfo("player") and CJ_HP("player") < 25 and (select(1,UnitChannelInfo("player")) ~= "Drain Life") then
		if CJ_Cast("Drain Life") then return end
	end
	
	if not UnitCastingInfo("player") and (UnitClass("target") == "Warrior" or UnitClass("target") == "Death Knight" or UnitClass("target") == "Rogue" or UnitClass("target") == "Hunter") and not CJ_HD("Curse of Exhaustion") then
		if CJ_Cast("Curse of Exhaustion") then return end
	end

	if not UnitCastingInfo("player") and (UnitClass("target") == "Priest" or UnitClass("target") == "Warlock" or UnitClass("target") == "Mage" or UnitClass("target") == "Shaman") and not CJ_HD("Curse of Tongues") then
		if CJ_Cast("Curse of Tongues") then return end
	end
		
	if not UnitCastingInfo("player") and (UnitClass("target") == "Paladin" or UnitClass("target") == "Druid") and (UnitPowerMax("target") > 30000) and not CJ_HD("Curse of Tongues") then
		if CJ_Cast("Curse of Tongues") then return end
	end

	if not UnitCastingInfo("player") and CJ_DTR("Corruption") < 2 then
		if CJ_Cast("Corruption") then return end;
	end

	if not UnitCastingInfo("player") and not CJ_HD("Bane of Agony") and not CJ_HD("Bane of Doom") then
		if CJ_Cast("Bane of Agony") then return end
	end

	if not (UnitGUID("target") == (UnitGUID("focus"))) and hasFocus and not CJ_HB("Soul Swap") and not (UnitDebuff("focus","Fear") or UnitDebuff("focus","Banish") or UnitDebuff("focus","Howl of Terror") or UnitDebuff("focus","Seduction")) then
		if CJ_CastTarget("Soul Swap","target") then soulswap = true return end
	end

	if not UnitCastingInfo("player") and (CJ_DTR("Haunt") - (select(7,GetSpellInfo("Haunt"))/1000)) < 5 and (GetTime() - lasthauntcast > 3.5) then
		if CJ_Cast("Haunt") then lasthauntcast = GetTime() return end
	end
	
	if select(1,UnitChannelInfo("player")) == "Drain Life" then return end
	
	if not UnitCastingInfo("player") and CJ_HP("target") < 25 and (select(1,UnitChannelInfo("player")) ~= "Drain Soul") then
		if CJ_Cast("Drain Soul") then return end
	end
	
	if select(1,UnitChannelInfo("player")) == "Drain Soul" then return end
	
	if not UnitCastingInfo("player") then
		if CJ_Cast("Shadow Bolt") then return end
	end
end

---Shannox---
function AffLockShannoxRot()
	if AmIFacing == false then return end;
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
	if CJ_AffBuffs() then return end;
	
	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end
	
	if IsSpellInRange("Fel Flame") == 0 then return end;
	
	if GetUnitSpeed("player") > 0 then
		if not CJ_OD("Curse of the Elements") and not CJ_OD("Jinx: Curse of the Elements") then
			if CJ_Cast("Curse of the Elements") then return end;
		end
		
		if CJ_DTR("Corruption") < 2 then
			if CJ_Cast("Corruption") then return end;
		end
		
		if not CJ_HD("Bane of Doom") then
			if CJ_Cast("Bane of Doom") then return end
		end

		if CJ_HB("Shadow Trance") then
			if CJ_Cast("Shadow Bolt") then return end
		end

		if PlayerToTarget < 10 then
			if CJ_Cast("Shadowflame") then return end;
		end
		
		if CJ_Cast("Fel Flame") then return end
		return
	end
	
	if not UnitCastingInfo("player") and not CJ_OD("Curse of the Elements") and not CJ_OD("Jinx: Curse of the Elements") then
		if CJ_Cast("Curse of the Elements") then return end;
	end
	
	if IsEquippedItem("Rune of Zeth") == 1 and GetItemCooldown(68998) == 0 and IsUsableItem("Rune of Zeth") == 1 and cj_cooldowns then
 		RunMacroText("/use Rune of Zeth");
 		return
	end

	if cj_cooldowns then
		CJ_Cast("Demon Soul");
		CJ_Cast("Blood Fury");
	end

	if not UnitCastingInfo("player") and CJ_IsBoss() and CJ_HB("Power Torrent") and CJ_HB("Lightweave") and CJ_HB("Demon Soul: Felhunter") and CJ_HB("Dire Magic") then
		if CJ_Cast("Summon Doomguard") then return end;
	end
	
	if not UnitCastingInfo("player") and CJ_DTRF("Corruption") < 2 then
		if CJ_CastTarget("Corruption","focus") then return end
	end
	
	if not UnitCastingInfo("player") and not CJ_HDF("Bane of Agony") then
		if CJ_CastTarget("Bane of Agony","focus") then return end
	end
	
	if not UnitCastingInfo("player") and (CJ_DTRF("Unstable Affliction") - (select(7,GetSpellInfo("Unstable Affliction"))/1000)) < 2 and (GetTime() - lastuacast > 2.5) 
		and GetUnitSpeed("player") == 0 then
		if CJ_CastTarget("Unstable Affliction","focus") then lastuacast = GetTime() return end
	end
	
	if not UnitCastingInfo("player") and (CJ_DTR("Haunt") - (select(7,GetSpellInfo("Haunt"))/1000)) < 5 and (GetTime() - lasthauntcast > 3.5) then
		if CJ_Cast("Haunt") then lasthauntcast = GetTime() return end
	end

	if not UnitCastingInfo("player") and CJ_DTR("Corruption") < 2 then
		if CJ_Cast("Corruption") then return end;
	end

	if not UnitCastingInfo("player") and not CJ_HD("Bane of Doom") then
		if CJ_Cast("Bane of Doom") then return end;
	end
	
	if not UnitCastingInfo("player") and (CJ_DTR("Unstable Affliction") - (select(7,GetSpellInfo("Unstable Affliction"))/1000)) < 4 and (GetTime() - lastuacast > 2.5) then
		if CJ_Cast("Unstable Affliction") then lastuacast = GetTime() return end
	end
	
	if not UnitCastingInfo("player") and CJ_HP("target") < 25 and (select(1,UnitChannelInfo("player")) ~= "Drain Soul") then
		if CJ_Cast("Drain Soul") then return end
	end
	
	if select(1,UnitChannelInfo("player")) == "Drain Soul" then return end
	
	if not UnitCastingInfo("player") and PlayerToTarget < 10 then
		if CJ_Cast("Shadowflame") then return end;
	end
	
	if not UnitCastingInfo("player") and CJ_HB("Shadow Trance") then
		if CJ_Cast("Shadow Bolt") then return end
	end
	
	if not UnitCastingInfo("player") then
		if CJ_Cast("Shadow Bolt") then return end
	end
end




---Domo Spirits---
function AffLockSpiritRot()
	if AmIFacing == false then return end;
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
	if CJ_AffBuffs() then return end;
	
	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end
	
	if IsSpellInRange("Fel Flame") == 0 then return end;
	
	if IsEquippedItem("Rune of Zeth") == 1 and GetItemCooldown(68998) == 0 and IsUsableItem("Rune of Zeth") == 1 and cj_cooldowns then
 		RunMacroText("/use Rune of Zeth");
 		return
	end

	if cj_cooldowns then
		CJ_Cast("Demon Soul");
		CJ_Cast("Blood Fury");
	end
	
	if not UnitCastingInfo("player") and (CJ_DTRF("Haunt") - (select(7,GetSpellInfo("Haunt"))/1000)) < 2 and (GetTime() - lasthauntcast > 2.5) 
		and GetUnitSpeed("player") == 0 then
		if CJ_CastTarget("Haunt","focus") then lasthauntcast = GetTime() return end
	end
	
	if not UnitCastingInfo("player") and CJ_DTRF("Corruption") < 2 then
		if CJ_CastTarget("Corruption","focus") then return end
	end
	
	if not UnitCastingInfo("player") and not CJ_HDF("Bane of Doom") then
		if CJ_CastTarget("Bane of Doom","focus") then return end
	end
	
	if not UnitCastingInfo("player") and (CJ_DTRF("Unstable Affliction") - (select(7,GetSpellInfo("Unstable Affliction"))/1000)) < 2 and (GetTime() - lastuacast > 2.5) 
		and GetUnitSpeed("player") == 0 then
		if CJ_CastTarget("Unstable Affliction","focus") then lastuacast = GetTime() return end
	end
	
	if not UnitCastingInfo("player") and PlayerToTarget < 10 then
		if CJ_Cast("Shadowflame") then return end;
	end

	if not UnitCastingInfo("player") and CJ_HP("target") < 25 and (select(1,UnitChannelInfo("player")) ~= "Drain Soul") then
		if CJ_Cast("Drain Soul") then return end
	end

	if not UnitCastingInfo("player") and CJ_HB("Shadow Trance") then
		if CJ_Cast("Shadow Bolt") then return end
	end

	if not UnitCastingInfo("player") and CJ_DTR("Corruption") < 2 then
		if CJ_Cast("Corruption") then return end;
	end
	
	if not UnitCastingInfo("player") then
		if CJ_Cast("Shadow Bolt") then return end
	end
end

---Ragnaros Sons---
function AffLockSonsRot()
	if AmIFacing == false then return end;
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
	if CJ_AffBuffs() then return end;
	
	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end
	
	if IsSpellInRange("Fel Flame") == 0 then return end;
	
	if UnitExists("pet") and not UnitIsDeadOrGhost("pet") and not IsPetAttackActive() then
		PetAttack("target")
	end
	
	if not UnitCastingInfo("player") and PlayerToTarget < 10 then
		if CJ_Cast("Shadowflame") then return end;
	end
	
	if not CJ_HB("Demon Soul: Felhunter") and cj_cooldowns then
		if CJ_Cast("Soulburn") then return end
	end
	
	if CJ_HB("Soulburn") then
		if CJ_Cast("Soul Fire") then return end
	end
	
	if CJ_HP("target") < 25 and (select(1,UnitChannelInfo("player")) ~= "Drain Soul") then
		if CJ_Cast("Drain Soul") then return end
	end
	
	if select(1,UnitChannelInfo("player")) == "Drain Soul" then return end
	
	if not UnitCastingInfo("player") and CJ_HB("Shadow Trance") then
		if CJ_Cast("Shadow Bolt") then return end
	end
	
	if not UnitCastingInfo("player") then
		if CJ_Cast("Shadow Bolt") then return end
	end

end

---Maloriak Heroic Swills---
function AffLockSwillRot()
	if CJ_HB("Soulburn") and not seedcast then
		if CJ_Cast("Seed of Corruption") then seedcast = true return end
	end

	if CJ_DTRF("Corruption") < 2 then
		if CJ_CastTarget("Corruption","focus") then return end
	end
	
	if not CJ_HDF("Bane of Doom") then
		if CJ_CastTarget("Bane of Doom","focus") then return end
	end
	
	if (CJ_DTRF("Unstable Affliction") - (select(7,GetSpellInfo("Unstable Affliction"))/1000)) < 4 and (GetTime() - lastuacast > 2.5) 
		and GetUnitSpeed("player") == 0 then
		if CJ_CastTarget("Unstable Affliction","focus") then lastuacast = GetTime() return end
	end
	
	if CJ_CD("Soulburn") == 0 and GetUnitSpeed("player") == 0 then
		if CJ_Cast("Soulburn") then if CJ_Cast("Seed of Corruption") then seedcast = true return end end
	end
	
	if not CJ_HD("Bane of Agony") and not CJ_HD("Bane of Doom") then
		if CJ_Cast("Bane of Agony") then return end
	end
	
	if not seedcast then
		if CJ_Cast("Seed of Corruption") then seedcast = true return end
	end
	
	if seedcast then
		seedcast = false;
		RunMacroText("/targetenemy");
	end
end

---Bethilac Spiderlings---
function AffLockSpiderlingsRot()
	if AmIFacing == false then return end;
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
	if CJ_AffBuffs() then return end;
	
	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end
	
	if IsSpellInRange("Fel Flame") == 0 then return end;
	
	if CJ_HB("Soulburn") then
		if CJ_Cast("Seed of Corruption") then return end
	end

	if CJ_CD("Soulburn") == 0 and GetUnitSpeed("player") == 0 then
		if CJ_Cast("Soulburn") then return end
	end
	
	if CJ_Cast("Seed of Corruption") then return end
	
end

---Bethilac Spinners---
function AffLockSpinnerRot()
	local hasFocus = false
	if CJ_OC() then StopAttack() return end
	CJ_PetInterrupt("Spell Lock");
	
	if UnitExists("pet") and not UnitIsDeadOrGhost("pet") and not IsPetAttackActive() then
		PetAttack("target")
	end

	if AmIFacing == false then return end;
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
	if CJ_AffBuffs() then return end;
	
	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end
	
	if IsSpellInRange("Fel Flame") == 0 then return end;
	
	if IsEquippedItem("Rune of Zeth") == 1 and GetItemCooldown(68998) == 0 and IsUsableItem("Rune of Zeth") == 1 and cj_cooldowns then
 		RunMacroText("/use Rune of Zeth");
 		return
	end

	if cj_cooldowns then
		CJ_Cast("Demon Soul");
		CJ_Cast("Blood Fury");
	end
	
	if GetUnitSpeed("player") > 0 then
		if CJ_DTR("Corruption") < 2 then
			if CJ_Cast("Corruption") then return end;
		end
		
		if CJ_HB("Shadow Trance") then
			if CJ_Cast("Shadow Bolt") then return end
		end
		
		if PlayerToTarget < 10 then
			if CJ_Cast("Shadowflame") then return end;
		end

		if CJ_Cast("Fel Flame") then return end
		return
	end

	if not UnitCastingInfo("player") and CJ_DTR("Corruption") < 2 then
		if CJ_Cast("Corruption") then return end;
	end

	if CJ_HP("target") < 25 and (select(1,UnitChannelInfo("player")) ~= "Drain Soul") then
		if CJ_Cast("Drain Soul") then return end
	end
	
	if select(1,UnitChannelInfo("player")) == "Drain Soul" then return end
	
	if not UnitCastingInfo("player") and PlayerToTarget < 10 then
		if CJ_Cast("Shadowflame") then return end;
	end
	
	if not UnitCastingInfo("player") and CJ_HB("Shadow Trance") then
		if CJ_Cast("Shadow Bolt") then return end
	end
	
	if not UnitCastingInfo("player") then
		if CJ_Cast("Shadow Bolt") then return end
	end

end

---Affliction Buffs---
function CJ_AffBuffs()
	if UnitExists("pet") and not CJ_HB("Soul Link") then
		if CJ_Cast("Soul Link") then return true end
	end
	if not CJ_HB("Fel Armor") then
		if CJ_Cast("Fel Armor") then return true end
	end
	return false
end

---General Affliction Rotation
function CJAffLockRot()
	local hasFocus = false
	if CJ_OC() then StopAttack() return end
	CJ_PetInterrupt("Spell Lock");
	
	if UnitExists("pet") and not UnitIsDeadOrGhost("pet") and not IsPetAttackActive() then
		PetAttack("target")
	end

	---SPECIAL PVP RULES---
	if ((select(2,GetInstanceInfo()) == "arena") or (select(2,GetInstanceInfo()) == "pvp")) then
		AffLockPvpRot()
		return
	end
	---SPECIAL TARGET FUNCTIONS---
	
	if UnitExists("focus") and UnitCanAttack("player","focus") and (UnitName("focus") ~= "Maloriak" or UnitName("focus") ~= "Majordomo Staghelm" or UnitName("focus") ~= "Shannox" or UnitName("focus") ~= "Riplimb" or UnitName("focus") ~= "Rageface") and UnitGUID("target") ~= UnitGUID("focus") then
		hasFocus = true
	else
		hasFocus = false;
	end
	
	if UnitName("target") == "Maloriak" and (UnitName("focus") ~= "Maloriak" or not UnitExists("focus")) then
		RunMacroText("/focus");
	end

	if UnitName("target") == "Majordomo Staghelm" and (UnitName("focus") ~= "Majordomo Staghelm" or not UnitExists("focus")) then
		RunMacroText("/focus");
	end
	
	
	if UnitName("target") == "Vile Swill" then
		AffLockSwillRot()
		return
	end

	
	if UnitName("target") == "Son of Flame" then
		AffLockSonsRot()
		return
	end

	if UnitName("target") == "Cinderweb Spiderling" then
		AffLockSpiderlingsRot()
		return
	end

	if UnitName("target") == "Cinderweb Spinner" then
		AffLockSpinnerRot()
		return
	end
	
	if UnitName("target") == "Alysrazor" then
		AffLockAlysRot()
		return
	end

	--"Blazing Talon Initiate"
	--"Spirit of the Flame"
	if UnitName("target") == "Spirit of the Flame" then
		AffLockSpiritRot()
		return
	end

	---Shannox, Riplimb, Ripface---
	if (UnitName("target") == "Shannox") then
		AffLockShannoxRot()
		return
	end

	--Testing of specific rotations---
	--"Raider's Training Dummy"  TEST
	--if UnitName("target") == "Raider's Training Dummy" then
	--	AffLockPvpRot()
	--	return
	--end
	
	--Alysrazor focus for when on ground---
	--if UnitName("target") == "Alysrazor" and (UnitName("focus") ~= "Alysrazor" or not UnitExists("focus")) then
	--	RunMacroText("/focus");
	--end
	
	if AmIFacing == false then return end;
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
	if CJ_AffBuffs() then return end;
	
	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end
	
	if IsSpellInRange("Fel Flame") == 0 then return end;
	
	CJ_OffensiveDispelPet("Devour Magic");
	
	--and PlayerToFocus < 40
	if not UnitCastingInfo("player") and CJ_HB("Soul Swap") and hasFocus and PlayerToFocus < 40 and not (UnitGUID("target") == UnitGUID("focus")) and not (UnitDebuff("focus","Fear") or UnitDebuff("focus","Banish") or UnitDebuff("focus","Howl of Terror") or UnitDebuff("focus","Seduction")) then
		if CJ_CastTarget("Soul Swap","focus") then return end;
	end
	
	if GetUnitSpeed("player") > 0 then
		if not CJ_OD("Curse of the Elements") and not CJ_OD("Jinx: Curse of the Elements") then
			if CJ_Cast("Curse of the Elements") then return end;
		end
		
		if CJ_DTR("Corruption") < 2 then
			if CJ_Cast("Corruption") then return end;
		end
		
		if hasFocus or not CJ_IsBoss() or (CJ_IsBoss() and UnitHealth("target") < 60000) then
			if not CJ_HD("Bane of Agony") then
				if CJ_Cast("Bane of Agony") then return end;
			end
		else
		        if not CJ_HD("Bane of Doom") then
				if CJ_Cast("Bane of Doom") then return end
			end
		end
		
		if CJ_HB("Shadow Trance") then
			if CJ_Cast("Shadow Bolt") then return end
		end
		
		if PlayerToTarget < 10 then
			if CJ_Cast("Shadowflame") then return end;
		end

		if CJ_Cast("Fel Flame") then return end
		return
	end
	
	if not CJ_OD("Curse of the Elements") and not CJ_OD("Jinx: Curse of the Elements") then
		if CJ_Cast("Curse of the Elements") then return end;
	end

	if cj_aoemode then
		if PlayerToTarget < 10 then
			if CJ_Cast("Shadowflame") then return end;
		end
		if CJ_Cast("Soulburn") then return end;

		if not CJ_HD("Seed of Corruption") then
			if CJ_Cast("Seed of Corruption") then return end;
		end
		
	end
	
	if IsEquippedItem("Rune of Zeth") == 1 and GetItemCooldown(68998) == 0 and IsUsableItem("Rune of Zeth") == 1 and cj_cooldowns then
 		RunMacroText("/use Rune of Zeth");
 		return
	end

	if cj_cooldowns then
		CJ_Cast("Demon Soul");
		CJ_Cast("Blood Fury");
	end

	if not UnitCastingInfo("player") and CJ_IsBoss() and CJ_HB("Power Torrent") and CJ_HB("Lightweave") and CJ_HB("Demon Soul: Felhunter") and CJ_HB("Mark of the Firelord") and not (UnitName("target") == "Alysrazor") then
		if CJ_Cast("Summon Doomguard") then return end;
	end
	
	if not UnitCastingInfo("player") and (CJ_DTR("Haunt") - (select(7,GetSpellInfo("Haunt"))/1000)) < 5 and (GetTime() - lasthauntcast > 3.5) then
		if CJ_Cast("Haunt") then lasthauntcast = GetTime() return end
	end

	if not UnitCastingInfo("player") and CJ_DTR("Corruption") < 2 then
		if CJ_Cast("Corruption") then return end;
	end
	
	if not UnitCastingInfo("player") and (CJ_DTR("Unstable Affliction") - (select(7,GetSpellInfo("Unstable Affliction"))/1000)) < 4 and (GetTime() - lastuacast > 2.5) then
		if CJ_Cast("Unstable Affliction") then lastuacast = GetTime() return end
	end

	if hasFocus or not CJ_IsBoss() or (CJ_IsBoss() and UnitHealth("target") < 60000) then
		if not CJ_HD("Bane of Agony") then
			if CJ_Cast("Bane of Agony") then return end;
		end
	else
	        if not CJ_HD("Bane of Doom") then 
			if CJ_Cast("Bane of Doom") then return end;
		end
	end
	
	if not (UnitGUID("target") == (UnitGUID("focus"))) and hasFocus and not CJ_HB("Soul Swap") and not (UnitDebuff("focus","Fear") or UnitDebuff("focus","Banish") or UnitDebuff("focus","Howl of Terror") or UnitDebuff("focus","Seduction")) then
		if CJ_CastTarget("Soul Swap","target") then soulswap = true return end
	end
	
	if CJ_HP("target") < 25 and (select(1,UnitChannelInfo("player")) ~= "Drain Soul") then
		if CJ_Cast("Drain Soul") then return end
	end
	
	if select(1,UnitChannelInfo("player")) == "Drain Soul" then return end
	
	if not UnitCastingInfo("player") and PlayerToTarget < 10 then
		if CJ_Cast("Shadowflame") then return end;
	end
	
	if not UnitCastingInfo("player") and CJ_HB("Shadow Trance") then
		if CJ_Cast("Shadow Bolt") then return end
	end
	
	if not UnitCastingInfo("player") then
		if CJ_Cast("Shadow Bolt") then return end
	end
end

-----------------------------
---------Destruction---------
-----------------------------
function CJ_DestroBuffs()
	if UnitExists("pet") and not CJ_HB("Soul Link") then
		if CJ_Cast("Soul Link") then return true end
	end
	if not CJ_HB("Fel Armor") then
		if CJ_Cast("Fel Armor") then return true end
	end
	return false
end


function CJDestLockSpinnerRot()
	if CJ_OC() then StopAttack() return end
	if AmIFacing == false then return end;
	
	if UnitExists("pet") and not UnitIsDeadOrGhost("pet") and not IsPetAttackActive() then
		PetAttack("target")
	end
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
	if CJ_DestroBuffs() then return end;
		
	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end

	if IsSpellInRange("Fel Flame") == 0 then return end;
	
	if GetUnitSpeed("player") > 0 then
		if CJ_HD("Immolate") and CJ_DTR("Immolate") < 8 then
			if CJ_Cast("Fel Flame") then return end
		end
		
		if CJ_DTR("Corruption") < 2 then
			if CJ_Cast("Corruption") then return end;
		end
		
		if CJ_Cast("Fel Flame") then return end
		return
	end

	if IsEquippedItem("Rune of Zeth") == 1 and GetItemCooldown(68998) == 0 and IsUsableItem("Rune of Zeth") == 1 and cj_cooldowns then
 		RunMacroText("/use Rune of Zeth");
 		return
	end

	if cj_cooldowns then
		CJ_Cast("Demon Soul");
		CJ_Cast("Blood Fury");
	end

	if not UnitCastingInfo("player") and (CJ_BTR("Improved Soul Fire") - ((select(7,GetSpellInfo("Soul Fire"))/1000)) + .5) < 5 and (GetTime() - lastsoulfirecast > 3.5) then
		if CJ_Cast("Soul Fire") then lastsoulfirecast = GetTime() return end
	end

	if not UnitCastingInfo("player") and (CJ_DTR("Immolate") - (select(7,GetSpellInfo("Immolate"))/1000)) < 2 and (GetTime() - lastimmolatecast > 2.5) then
		if CJ_Cast("Immolate") then lastimmolatecast = GetTime() return end
	end

        if CJ_Cast("Conflagrate") then return end

	 if PlayerToTarget < 10 then
		if CJ_Cast("Shadowflame") then return end
	end

        if CJ_HB("Empowered Imp") and (CJ_BTR("Empowered Imp") < CJ_BTR("Improved Soul Fire") + .5) then
		if CJ_Cast("Soul Fire") then return end
	end

        if CJ_Cast("Chaos Bolt") then return end

        if CJ_HP("target") < 20 and CJ_Cast("Shadowburn") then return end

        if CJ_Cast("Incinerate") then return end
end

function CJDestLockRot()
	if CJ_OC() then StopAttack() return end
	if AmIFacing == false then return end;
	
	if UnitExists("pet") and not UnitIsDeadOrGhost("pet") and not IsPetAttackActive() then
		PetAttack("target")
	end
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
	if CJ_DestroBuffs() then return end;
		
	if UnitName("target") == "Cinderweb Spinner" then
		CJDestLockSpinnerRot()
		return
	end

	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end
	
	if IsSpellInRange("Fel Flame") == 0 then return end;
	
	if GetUnitSpeed("player") > 0 then
		if CJ_HD("Immolate") and CJ_DTR("Immolate") < 8 then
			if CJ_Cast("Fel Flame") then return end
		end
		
		if not CJ_OD("Curse of the Elements") and not CJ_OD("Jinx: Curse of the Elements") then
			if CJ_Cast("Curse of the Elements") then return end;
		end
		
		if CJ_DTR("Corruption") < 2 then
			if CJ_Cast("Corruption") then return end;
		end
		
		if not CJ_IsBoss() or (CJ_IsBoss() and UnitHealth("target") < 60000) then
			if not CJ_HD("Bane of Agony") then
				if CJ_Cast("Bane of Agony") then return end;
			end
		else
		        if not CJ_HD("Bane of Doom") then
				if CJ_Cast("Bane of Doom") then return end
			end
		end
			
		if CJ_Cast("Fel Flame") then return end
		return
	end

	if IsEquippedItem("Rune of Zeth") == 1 and GetItemCooldown(68998) == 0 and IsUsableItem("Rune of Zeth") == 1 and cj_cooldowns then
 		RunMacroText("/use Rune of Zeth");
 		return
	end

	if cj_cooldowns then
		CJ_Cast("Demon Soul");
		CJ_Cast("Blood Fury");
	end
	
	if not UnitCastingInfo("player") and not CJ_OD("Curse of the Elements") and not CJ_OD("Jinx: Curse of the Elements") then
		if CJ_Cast("Curse of the Elements") then return end;
	end
	
        if not UnitCastingInfo("player") and (CJ_BTR("Improved Soul Fire") - ((select(7,GetSpellInfo("Soul Fire"))/1000)) + .5) < 5 and (GetTime() - lastsoulfirecast > 3.5) then
		if CJ_Cast("Soul Fire") then lastsoulfirecast = GetTime() return end
	end

	if not UnitCastingInfo("player") and (CJ_DTR("Immolate") - (select(7,GetSpellInfo("Immolate"))/1000)) < 2 and (GetTime() - lastimmolatecast > 2.5) then
		if CJ_Cast("Immolate") then lastimmolatecast = GetTime() return end
	end

        if CJ_Cast("Conflagrate") then return end
	
	if not CJ_IsBoss() or (CJ_IsBoss() and UnitHealth("target") < 60000) then
		if not CJ_HD("Bane of Agony") then
			if CJ_Cast("Bane of Agony") then return end;
		end
	else
	        if not CJ_HD("Bane of Doom") then
			if CJ_Cast("Bane of Doom") then return end
		end
	end
	
	if CJ_DTR("Corruption") < 2 then
		if CJ_Cast("Corruption") then return end;
	end

        if PlayerToTarget < 10 then
		if CJ_Cast("Shadowflame") then return end
	end

        if CJ_HB("Empowered Imp") and (CJ_BTR("Empowered Imp") < CJ_BTR("Improved Soul Fire") + .5) then
		if CJ_Cast("Soul Fire") then return end
	end

        if CJ_Cast("Chaos Bolt") then return end

        if CJ_HP("target") < 20 and CJ_Cast("Shadowburn") then return end

        if CJ_Cast("Incinerate") then return end
end

-----------------------------
---------Demonology----------
-----------------------------
function CJ_DemoBuffs()
if UnitExists("pet") and not CJ_HB("Soul Link") then
	if CJ_Cast("Soul Link") then return true end
end

if not CJ_HB("Fel Armor") then
		if CJ_Cast("Fel Armor") then return true end
	end
		return false
end

function DemoLockPvpRot()

if UnitExists("pet") and not UnitIsDeadOrGhost("pet") and not CJ_HB("Soul Link") then
	if CJ_Cast("Soul Link") then return true end
end

if ((select(2,GetInstanceInfo()) == "arena") or (select(2,GetInstanceInfo()) == "pvp")) then
	if CJ_HP("player") > 65 and not CJ_HB("Fel Armor") then
		if CJ_Cast("Fel Armor") then return true end
	end
	if CJ_HP("player") < 50 and not CJ_HB("Demon Armor") then
		if CJ_Cast("Demon Armor") then return true end
	end
end
	
	if CJ_OC() then StopAttack() return end
	

	if UnitExists("pet") and not UnitIsDeadOrGhost("pet") and not IsPetAttackActive() and not cj_aoemode then
		PetAttack("target")
	end
	
	if AmIFacing == false then return end;
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
		
	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end
	
	if IsSpellInRange("Fel Flame") == 0 then return end;
	
	
	if not UnitCastingInfo("player") and CJ_HP("player") < 30 then
		if CJ_Cast("Soulburn") then return end
	end

	if not UnitCastingInfo("player") and CJ_HP("player") < 30 and CJ_HB("Soulburn") then
		RunMacroText("/use Healthstone");
	end

	if GetUnitSpeed("player") > 0 and not cj_aoemode then
		
		if not UnitCastingInfo("player") and (UnitClass("target") == "Priest" or UnitClass("target") == "Warlock" or UnitClass("target") == "Mage") and not CJ_HD("Curse of Tongues") then
			if CJ_Cast("Curse of Tongues") then return end
		end
		
		if not UnitCastingInfo("player") and (UnitClass("target") == "Paladin" or UnitClass("target") == "Druid"  or UnitClass("target") == "Shaman") and (UnitPowerMax("target") > 40000) and not CJ_HD("Curse of Tongues") then
			if CJ_Cast("Curse of Tongues") then return end
		end
		
		if not UnitCastingInfo("player") and (UnitClass("target") == "Warrior" or UnitClass("target") == "Death Knight" or UnitClass("target") == "Rogue" or UnitClass("target") == "Hunter") and not CJ_HD("Curse of Weakness") then
			if CJ_Cast("Curse of Weakness") then return end
		end
		
		if CJ_DTR("Corruption") < 2 then
			if CJ_Cast("Corruption") then return end;
		end
		
		if not CJ_IsBoss() or (CJ_IsBoss() and UnitHealth("target") < 60000) or (UnitName("target") == "Left Foot") or (UnitName("target") == "Right Foot") then
			if not CJ_HD("Bane of Agony") then
				if CJ_Cast("Bane of Agony") then return end;
			end
		else
			if not CJ_HD("Bane of Doom") then 
				if CJ_Cast("Bane of Doom") then return end;
			end
		end
					
		if CJ_HB("Shadow Trance") then
			if CJ_Cast("Shadow Bolt") then return end
		end
		
		if PlayerToTarget < 10 then
			if CJ_Cast("Shadowflame") then return end;
		end

		if CJ_Cast("Fel Flame") then return end
		return
	end
	
	if not UnitCastingInfo("player") and (UnitClass("target") == "Priest" or UnitClass("target") == "Warlock" or UnitClass("target") == "Mage") and not CJ_HD("Curse of Tongues") then
		if CJ_Cast("Curse of Tongues") then return end
	end
		
	if not UnitCastingInfo("player") and (UnitClass("target") == "Paladin" or UnitClass("target") == "Druid"  or UnitClass("target") == "Shaman") and (UnitPowerMax("target") > 40000) and not CJ_HD("Curse of Tongues") then
		if CJ_Cast("Curse of Tongues") then return end
	end
		
	if not UnitCastingInfo("player") and (UnitClass("target") == "Warrior" or UnitClass("target") == "Death Knight" or UnitClass("target") == "Rogue" or UnitClass("target") == "Hunter") and not CJ_HD("Curse of Weakness") then
		if CJ_Cast("Curse of Weakness") then return end
	end

	if not UnitCastingInfo("player") and cj_cooldowns then
		RunMacroText("/use Vicious Gladiator's Badge of Dominance");
	end

	if not UnitCastingInfo("player") and cj_cooldowns then
		if CJ_Cast("Demon Soul") then return end
		if CJ_Cast("Blood Fury") then return end
		if CJ_Cast("Metamorphosis") then return end
	end

	--and PlayerToTarget <= 8
	if not UnitCastingInfo("player") and CJ_BTR("Metamorphosis") > 3 and PlayerToTarget <= 16 then
		if CJ_Cast("Immolation Aura") then return end
		if CJ_Cast("Demon Leap") then return end
	end
	
	if not CJ_IsBoss() or (CJ_IsBoss() and UnitHealth("target") < 60000) or (UnitName("target") == "Left Foot") or (UnitName("target") == "Right Foot") then
		if not CJ_HD("Bane of Agony") then
			if CJ_Cast("Bane of Agony") then return end;
		end
	else
	        if not CJ_HD("Bane of Doom") then 
			if CJ_Cast("Bane of Doom") then return end;
		end
	end
			
	if not UnitCastingInfo("player") and not CJ_HD("Immolate") and GetTime() - lastimmolatecast > 4 then
		if CJ_Cast("Immolate") then lastimmolatecast = GetTime() return end
	end

	if not UnitCastingInfo("player") and CJ_Cast("Hand of Gul'dan") then return end
	
	if not UnitCastingInfo("player") and CJ_DTR("Corruption") < 3 then
		if CJ_Cast("Corruption") then return end
	end
	
	--PlayerToTarget < 10
	if not UnitCastingInfo("player") and PlayerToTarget < 10 then
		if CJ_Cast("Shadowflame") then return end
	end
	
	if not UnitCastingInfo("player") and CJ_HB("Molten Core") then
		if CJ_Cast("Incinerate") then return end
	end
	
	if not UnitCastingInfo("player") and CJ_HB("Decimation") or CJ_HB("Soulburn") then
		if CJ_Cast("Soul Fire") then return end
	end
	
	if not UnitCastingInfo("player") and CJ_HB("Shadow Trance") then
		if CJ_Cast("Shadow Bolt") then return end
	end
	
	if not UnitCastingInfo("player") then
		if CJ_Cast("Shadow Bolt") then return end
	end
end


function CJDemoLockRot()
	
	if ((select(2,GetInstanceInfo()) == "arena") or (select(2,GetInstanceInfo()) == "pvp")) then
		DemoLockPvpRot()
		return
	end

	if CJ_OC() then StopAttack() return end
	if UnitExists("pet") then
		CJ_PetInterrupt("Spell Lock");
	end

	if UnitExists("pet") and not UnitIsDeadOrGhost("pet") and not IsPetAttackActive() and not cj_aoemode then
		PetAttack("target")
	end
	
	if AmIFacing == false then return end;
	
	if not CJ_GCD() then return end;
	if CJ_Casting() then return end
	if CJ_DemoBuffs() then return end;

	if ((select(2,GetInstanceInfo()) == "arena") or (select(2,GetInstanceInfo()) == "pvp")) then
		DemoLockPvpRot()
		return
	end
	
	if UnitPower("player") < ((UnitHealthMax("player")*.15)*1.4)  and CJ_HP("player") > 20 and cj_lifetap then
		if CJ_Cast("Life Tap") then return end
	end
	
	if IsSpellInRange("Fel Flame") == 0 then return end;
	CJ_OffensiveDispelPet("Devour Magic");
	
	if GetUnitSpeed("player") > 0 and not cj_aoemode then
		if not CJ_OD("Curse of the Elements") and not CJ_OD("Jinx: Curse of the Elements") then
			if CJ_Cast("Curse of the Elements") then return end;
		end
		
		if CJ_DTR("Corruption") < 2 then
			if CJ_Cast("Corruption") then return end;
		end
		
		if not CJ_IsBoss() or (CJ_IsBoss() and UnitHealth("target") < 60000) or (UnitName("target") == "Left Foot") or (UnitName("target") == "Right Foot") then
			if not CJ_HD("Bane of Agony") then
				if CJ_Cast("Bane of Agony") then return end;
			end
		else
			if not CJ_HD("Bane of Doom") then 
				if CJ_Cast("Bane of Doom") then return end;
			end
		end
					
		if CJ_HB("Shadow Trance") then
			if CJ_Cast("Shadow Bolt") then return end
		end
		
		if PlayerToTarget < 10 then
			if CJ_Cast("Shadowflame") then return end;
		end

		if CJ_Cast("Fel Flame") then return end
		return
	end
	
	if not UnitCastingInfo("player") and not CJ_OD("Curse of the Elements") and not CJ_OD("Jinx: Curse of the Elements") then
		if CJ_Cast("Curse of the Elements") then return end;
	end
	
	if not UnitCastingInfo("player") and IsEquippedItem("Rune of Zeth") == 1 and GetItemCooldown(68998) == 0 and IsUsableItem("Rune of Zeth") == 1 and cj_cooldowns then
 		RunMacroText("/use Rune of Zeth");
 		return
	end
	
	if not UnitCastingInfo("player") and cj_cooldowns then
		if CJ_Cast("Demon Soul") then return end
		if CJ_Cast("Blood Fury") then return end
		if CJ_Cast("Metamorphosis") then return end
		
	end

	--and PlayerToTarget <= 8
	if not UnitCastingInfo("player") and CJ_BTR("Metamorphosis") > 3 and PlayerToTarget <= 8 then
		if CJ_Cast("Immolation Aura") then return end
	end
	
	if not UnitCastingInfo("player") and cj_aoemode and PlayerToTarget > 7 then
		if CJ_Cast("Felstorm") then PetFollow() return end
	end

	--and PlayerToTarget < 7
	if not UnitCastingInfo("player") and cj_aoemode and PlayerToTarget < 7 then
		if CJ_Cast("Shadowflame") then return end
		if GetUnitSpeed("player") == 0 then
			if CJ_Cast("Hand of Gul'dan") then return end
		end
		if CJ_Cast("Felstorm") then return end
		if CJ_Cast("Hellfire") then return end
		
	end
	
	if not CJ_IsBoss() or (CJ_IsBoss() and UnitHealth("target") < 60000) or (UnitName("target") == "Left Foot") or (UnitName("target") == "Right Foot") then
		if not CJ_HD("Bane of Agony") then
			if CJ_Cast("Bane of Agony") then return end;
		end
	else
	        if not CJ_HD("Bane of Doom") then 
			if CJ_Cast("Bane of Doom") then return end;
		end
	end
			
	if not UnitCastingInfo("player") and not CJ_HD("Immolate") and GetTime() - lastimmolatecast > 4 then
		if CJ_Cast("Immolate") then lastimmolatecast = GetTime() return end
	end

	if not UnitCastingInfo("player") and CJ_Cast("Hand of Gul'dan") then return end
	
	if not UnitCastingInfo("player") and CJ_DTR("Corruption") < 3 then
		if CJ_Cast("Corruption") then return end
	end
	
	--PlayerToTarget < 10
	if not UnitCastingInfo("player") and PlayerToTarget < 10 then
		if CJ_Cast("Shadowflame") then return end
	end
	
	if not UnitCastingInfo("player") and CJ_HB("Molten Core") then
		if CJ_Cast("Incinerate") then return end
	end
	
	if not UnitCastingInfo("player") and CJ_HB("Decimation") or CJ_HB("Soulburn") then
		if CJ_Cast("Soul Fire") then return end
	end
	
	if not UnitCastingInfo("player") and CJ_HB("Shadow Trance") then
		if CJ_Cast("Shadow Bolt") then return end
	end
	
	if not UnitCastingInfo("player") then
		if CJ_Cast("Shadow Bolt") then return end
	end
end